#pragma once
#include "CXcpObjectBase.h"
#include "NoBaseClass.h"
#include "CXcpObjectThreadSafeAddRefPolicy.h"
#include "CCachedSitePermission.h"

//typedef _DHCP_FILTER_LIST_TYPE Permission::Value;
class CPermissionEnumerator;


class CSitePermissions :
	public CXcpObjectBase<NoBaseClass,CXcpObjectThreadSafeAddRefPolicy>
{

public: 
	static HRESULT Create(struct IPALSettingsDictionaryNode *, const CXString *, CSitePermissions * *);
	const CXString * GetHost();
	HRESULT GetPermission(const XUINT16 *, XUINT32, enum Permission::Value *);
	HRESULT GetPermission(const CXString *, enum Permission::Value *);
	HRESULT RemovePermission(const XUINT16 *, XUINT32);
	HRESULT RemovePermission(const CXString *);
	HRESULT GetPermissionEnumerator(CPermissionEnumerator * *);
	XUINT32 IsAllowed(const XUINT16 *, XUINT32);
	XUINT32 IsAllowed(const CXString *);
	XUINT32 IsDenied(const XUINT16 *, XUINT32);
	XUINT32 IsDenied(const CXString *);
	HRESULT DenyOnce(const XUINT16 *, XUINT32);
	HRESULT DenyOnce(const CXString *);
	HRESULT DenyAlways(const XUINT16 *, XUINT32);
	HRESULT DenyAlways(const CXString *);
	HRESULT AllowOnce(const XUINT16 *, XUINT32);
	HRESULT AllowOnce(const CXString *);
	HRESULT AllowAlways(const XUINT16 *, XUINT32);
	HRESULT AllowAlways(const CXString *);

protected: 
	CSitePermissions();
	virtual ~CSitePermissions();
	HRESULT Initialize(struct IPALSettingsDictionaryNode *, const CXString *);
	HRESULT GetSiteNode(struct IPALSettingsDictionaryNode * *);
	HRESULT GetOrCreateSiteNode(struct IPALSettingsDictionaryNode * *);
	HRESULT GetPermissionNode(const CXString *, struct IPALSettingsIntegerNode * *);
	HRESULT PersistPermission(const CXString *, enum Permission::Value);
	HRESULT RemovePersistedPermission(const CXString *);
	HRESULT GetCachedPermission(const CXString *, CCachedSitePermission * *);
	HRESULT SetCachedPermission(const CXString *, enum Permission::Value);
	HRESULT RemoveCachedPermission(const CXString *);
	CXString * m_Host;
	xref_ptr<IPALSettingsDictionaryNode> m_SettingsStorage;
	xvector<xref_ptr<CCachedSitePermission> > m_CachedPermissions;
};

